package com.tanhua.admin.test;

import cn.hutool.core.date.*;
import org.junit.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class test {
   /* //日期的格式
    private static String dateFormat = "yyyy-MM-dd";

    public static void main(String[] args) {
        //获取今天的日期
        String today = DateUtil.format(new Date(), dateFormat);
        System.out.println(today);
        //获取上个月的时间
        String lastMonth = DateUtil.lastMonth().toString(dateFormat);
        System.out.println(lastMonth);


        //获取上个月份的天数
        String date = lastMonth;
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
        Calendar calendar = Calendar.getInstance();
        try {
            calendar.setTime(dateFormat.parse(date));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH));
        calendar.set(Calendar.DATE, 1);
        calendar.roll(Calendar.DATE, -1);
        int time1 = calendar.get(Calendar.DATE);
        System.out.println(time1);
    }*/

    /*//获取上个月的时间
    String lastMonth = DateUtil.lastMonth().toString(dateFormat);
    public static int getDaysOfMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    }

    public static void main(String[] args) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(getDaysOfMonth(sdf.parse("lastMonth")));

    }*/


    /**
     * 获取两个日期中的所有日期,并转换为表后缀
     *
     * @param begin 格式:yyyy-MM-dd'T'HH:mm:ss.SSS'Z'
     * @param end   格式:yyyy-MM-dd'T'HH:mm:ss.SSS'Z'
     * @return 格式:MM_dd
     */
    @Test
    public void  testgetDetHashList(String begin, String end) {
        List<String> hashList = new ArrayList<>();
        String btime = begin.substring(0, 10);//yyyy-MM-dd
        String etime = end.substring(0, 10);

        Date bDate = DateUtil.parse(btime, DatePattern.NORM_DATE_PATTERN);//yyyy-MM-dd
        Date eDate = DateUtil.parse(etime, DatePattern.NORM_DATE_PATTERN);
        List<DateTime> dateList = DateUtil.rangeToList(bDate, eDate, DateField.DAY_OF_YEAR);//创建日期范围生成器
        String hash = null;
        for (DateTime dt : dateList) {
            hash = dt.toString().replaceAll("-", "_").substring(5, 10);
            hashList.add(hash);
        }
        System.out.println(hashList);
    }

    @Test
    public void testsj (String begin, String end){
        List<String> hashList = new ArrayList<>();
        String btime = begin.substring(0, 10);//yyyy-MM-dd
        String etime = end.substring(0, 10);

        Date bDate = DateUtil.parse(btime, DatePattern.NORM_DATE_PATTERN);//yyyy-MM-dd
        Date eDate = DateUtil.parse(etime, DatePattern.NORM_DATE_PATTERN);
        List<DateTime> dateList = DateUtil.rangeToList(bDate, eDate, DateField.DAY_OF_YEAR);//创建日期范围生成器


    }

    //日期的格式
    private static String dateFormat = "yyyy-MM-dd";


        //获取今天的日期
        String today = DateUtil.format(new Date(), dateFormat);

        //获取上个月的时间
        String lastMonth = DateUtil.lastMonth().toString(dateFormat);


    public static void main(String[] args) {

        Month month = DateUtil.monthEnum(new Date());
        System.out.println(month);

    }
}
